6 红<template>
  <div class="app-container customer-div">
    <div style="margin-top: 20px">
      <!--搜索-->
      <el-form :inline="true" :model="listQuery" size="mini" label-width="130px">
        <el-form-item label="业务员：">
          <el-cascader
            size="mini"
            collapse-tags
            :show-all-levels="false"
            v-model="listQuery.userId"
            placeholder="请选择部门/事业部/人员"
            :options="userList"
            :props="props"></el-cascader>
        </el-form-item>
        <el-form-item label="订单编号：">
           <el-input v-model="listQuery.orderSn" clearable></el-input>
        </el-form-item>
        <el-form-item label="客户名称：">
          <el-select
            clearable
            v-model="listQuery.customerId"
            filterable
            remote
            reserve-keyword
            placeholder="请输入关键词"
            :remote-method="querySearch">
            <el-option
              v-for="item in querySearchList"
              :key="item.customerId"
              :label="item.customerName"
              :value="item.customerId">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="关闭原因：">
            <el-select clearable v-model="listQuery.orderCloseRemark">
               <el-option
                  v-for="item in reasonList"
                  :key="item"
                  :label="item"
                  :value="item">
               </el-option>
            </el-select>
        </el-form-item>

        <el-form-item label="关闭日期：">
          <el-date-picker
            v-model="listQuery.orderCloseTime"
            type="daterange"
            format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button
            @click="handleSearchList()"
            type="primary">
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-radio-group size="small" v-model="listQuery.isPreorder" @change="handleSearchList">
      <el-radio-button :label="1">预售订单</el-radio-button>
      <el-radio-button :label="0">非预售订单</el-radio-button>
    </el-radio-group>
    <!--数据列表-->
    <div class="table-container">
      <el-table
        v-loading="loading"
        :data="list"
        border
        style="width: 100%; margin-top: 20px">
        <el-table-column
          min-width="150"
          label="订单编号"
          align="center">
          <template slot-scope="scope">
            <el-link @click="toDetail(scope.row)" type="primary" >{{scope.row.orderSn}}</el-link>
          </template>
        </el-table-column>
        <el-table-column
          min-width="200"
          label="客户名称"
          align="center">
          <template slot-scope="scope">
            <div>{{scope.row.customerName}}</div>
          </template>
        </el-table-column>
        <el-table-column
          min-width="100"
          prop="userName"
          label="销售员"
          align="center">
        </el-table-column>
        <el-table-column
          min-width="100"
          prop="orderGoodsNum"
          align="center"
          label="订单数量">
        </el-table-column>
        <el-table-column
          min-width="100"
          prop="orderAmount"
          align="center"
          label="订单金额">
        </el-table-column>
        <el-table-column
          min-width="100"
          prop="orderCloseTime"
          align="center"
          label="关闭日期">
        </el-table-column>
        <el-table-column
          min-width="150"
          prop="orderCloseRemark"
          align="center"
          label="关闭原因">
        </el-table-column>
         <el-table-column
          min-width="100"
          fixed="right"
          align="center"
          label="操作">
           <template slot-scope="scope">
              <el-button
                v-if="listQuery.isPreorder == 1"
                size="mini"
                type="text"
                @click="seeFile(scope.row.orderCloseTipFile)">
                下载告知函
              </el-button>
           </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize"
        :page-sizes="[10,15,20]"
        :total="count">
      </el-pagination>
    </div>

  </div>
</template>

<script>
import { getOrderUsersList,getCustomerOption,getConfigList,orderClosedList} from '@/api/partner'
import {getCustomerInfoAPI} from '@/api/company'
import {manageTrackingList} from '@/api/fms'
import {saleUserList} from '@/api/data.js'
import {formatDate} from '@/utils/date';
import store from '@/store'
import { mapGetters } from 'vuex'
const defaultListQuery={
  "userId" : [],
  "orderSn" : "",
  "customerId" : '',
  "orderCloseRemark" : "", //订单关闭原因
  "orderCloseTime" : [],
  "isPreorder" : 1, //是否预售订单
  "pageNum" : 1,
  "pageSize" : 10
};
export default {
  name: "manageFmsList",
  data(){
    return{
      roles:store.getters.roles ? store.getters.roles : [],
      listQuery:JSON.parse(JSON.stringify(defaultListQuery)),
      list:[],
      count:0,
      loading:false,
      userList:[],
      customerList:[],
      loading2:false,
      btnloading:false,
      props:{multiple: true,label:'value',value:'label',emitPath:false},
      querySearchList:[],
      reasonList:['支付超期关闭','发货完成关闭','不执行手工关闭'],
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),


  },
  created() {
    this.getListData();
    this.getUserList();


  },
  filters: {
    formatTime(time) {
      let date = new Date(time);
      return formatDate(date, 'yyyy-MM-dd')
    },
  },
  methods:{
    //去详情页
    toDetail(item){
      let routeData = this.$router.resolve({name:'saleDetail',query:{id:item.orderId,type:'see'}});
      window.open(routeData.href);
    },
    seeFile(file){
      window.open(file)
    },
    getUserList(){
      saleUserList().then((res)=>{
        console.log(res)
        this.userList = res
      })
    },




    //客户名称输入匹配
    querySearch(queryString){
      let data = {};
      data.keywords = queryString;
      getCustomerOption(data).then((res)=>{
        this.querySearchList = res;
      })
    },

    handleSearchList(){
      this.listQuery.pageNum = 1;
      this.getListData();
    },

    handleSizeChange(val){
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getListData();
    },
    handleCurrentChange(val){
      this.listQuery.pageNum = val;
      this.getListData();
    },

    getListData(){
      this.loading = true;
      orderClosedList(this.listQuery).then((res)=>{
        this.list = res.list;
        this.count = res.count;
        this.loading = false;
      }).catch(()=>{
        this.loading = false;
      })
    },

  },
}
</script>


